<%@page import="java.net.URLEncoder"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="java.sql.ResultSet"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:useBean id="database" scope="request" class="accessibleworldsdatabase.AccessibleWorldsDatabaseJavaBeans"/>
<jsp:useBean id="des" scope="request" class="accessibleworldsdes.AccessibleWorldsDESJavaBeans"/>
<%try {

String accessCode = request.getParameter("accessCode");

if(!(accessCode==null || "".equals(accessCode))) {
	
    accessCode = des.decryptString(session.getId(), accessCode);
    accessCode = URLDecoder.decode(accessCode, "UTF-8");
    
    if(des.getAndroidAccessCode().equals(accessCode) || des.getComputerAccessCode().equals(accessCode)) {
    	
        String email = request.getParameter("email");
        String password = request.getParameter("password");

        if(!(email==null || "".equals(email) || password==null || "".equals(password))) {
            
            email = des.decryptString(session.getId(), email);
            password = des.decryptString(session.getId(), password);
            
            email = URLDecoder.decode(email, "UTF-8");
            password = URLDecoder.decode(password, "UTF-8");

            database.connect(des.decryptString(des.getServiceSecretKey(), database.getEncryptedPassword()));

            String SQL =
            "SELECT * FROM Users"+
            	" WHERE"+
            		" email = \""+email+"\""+
            		" AND password = \""+password+"\"";

            ResultSet resultSet = database.execSQL(SQL);

            if(resultSet.next()) {
                if("2".equalsIgnoreCase(resultSet.getString("U_type")) || "3".equalsIgnoreCase(resultSet.getString("U_type"))) {

                    String output = URLEncoder.encode("OK","UTF-8");
                    output = output+" "+URLEncoder.encode(resultSet.getString("user_id"),"UTF-8");
                    output = output+" "+URLEncoder.encode(resultSet.getString("email"),"UTF-8");
                    output = output+" "+URLEncoder.encode(resultSet.getString("password"),"UTF-8");
                    output = output+" "+URLEncoder.encode(resultSet.getString("lastName"),"UTF-8");
                    output = output+" "+URLEncoder.encode(resultSet.getString("firstName"),"UTF-8");
                    output = output+" "+URLEncoder.encode(resultSet.getString("birthday"),"UTF-8");

                    output = des.encryptString(session.getId(),output);
                    out.print(output);
                    
                }
                else if ("0".equalsIgnoreCase(resultSet.getString("U_type"))) {
                	 String output = URLEncoder.encode("OK","UTF-8");
                     output = output+" "+URLEncoder.encode("Blocked!!!","UTF-8");
                     
                     output = des.encryptString(session.getId(),output);
                     out.print(output);
                }
                else {
                    String output = URLEncoder.encode("OK","UTF-8");
                    output = output+" "+URLEncoder.encode("Not Activated!!!","UTF-8");
                    
                    output = des.encryptString(session.getId(),output);
                    out.print(output);
                }
            }
            else {
                String output = URLEncoder.encode("OK","UTF-8");
                output = output+" "+URLEncoder.encode("Not Exist!!!","UTF-8");
                
                output = des.encryptString(session.getId(),output);
                out.print(output);
            }
            
            database.closeConnection();
        }
    }
}
} catch (Exception ex) {}%>